package com.demo.controllers;

import com.demo.entity.User;
import com.demo.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * @Description:
 * @author: fanfan
 * @date: 2018/6/19 10:16
 */
@RequestMapping("/")
@RestController
public class LoginController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public void login(HttpServletRequest request){
        HttpSession session=request.getSession();
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        User user= userService.findUserByUsername(username);
        if (user.getPassword().equals(password)){
            session.setAttribute("User",user);
        }
    }

    @RequestMapping("/getSession")
    public User getSession(HttpServletRequest request){
        User user=(User) request.getSession().getAttribute("User");
        return user;
    }
}
